import 'package:bruno/bruno.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import '../../../main.dart';
import '../../../r.dart';
import '../../../values/MyColors.dart';
import '../../../widget/ImagesGridviewWidget.dart';
import 'complete_poll_logic.dart';

/// 完成调研
class CompletePollPage extends StatefulWidget {
  final String title;

  const CompletePollPage({Key? key, required this.title}) : super(key: key);

  @override
  State<CompletePollPage> createState() => _CompletePollPageState();
}

class _CompletePollPageState extends State<CompletePollPage> {
  final logic = Get.put(CompletePollLogic());
  final state = Get.find<CompletePollLogic>().state;

  @override
  Widget build(BuildContext context) {
    return GetBuilder<CompletePollLogic>(builder: (logic) {
      return Scaffold(
        backgroundColor: MyColors.FFEDF1F5,
        appBar: BrnAppBar(title: "填写证明资料", themeData: XxxConfigUtils.defaultAppBarConfig),
        body: Stack(
          children: [
            Image.asset(R.assetsImgBgHome3, fit: BoxFit.fitWidth),
            SingleChildScrollView(
              child: Column(
                children: [
                  Center(
                    child: Column(
                      children: [
                        Padding(
                          padding: EdgeInsets.only(top: 20.r),
                          child: Image.asset(R.assetsImgIconHome9, width: 69.5.r),
                        ),
                        Padding(
                          padding: EdgeInsets.only(top: 20.r),
                          child: Text("答卷已经提交，感谢您的参与!", style: TextStyle(color: Colors.white, fontSize: 16.r)),
                        ),
                      ],
                    ),
                  ),
                  Container(
                    margin: EdgeInsets.only(top: 32.r),
                    decoration: BoxDecoration(
                      color: MyColors.FFEDF1F5,
                      borderRadius: BorderRadius.only(
                        topLeft: Radius.circular(15.r),
                        topRight: Radius.circular(15.r),
                      ),
                    ),
                    child: Column(
                      children: [
                        Visibility(
                          visible: state.isSignature,
                          child: Container(
                            margin: EdgeInsets.fromLTRB(15.5.r, 15.r, 15.5.r, 0),
                            padding: EdgeInsets.only(left: 14.5.r, right: 24.r),
                            height: 52.r,
                            decoration: BoxDecoration(
                              color: Colors.white,
                              borderRadius: BorderRadius.all(Radius.circular(6.r)),
                            ),
                            child: Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                Text("受访者签名", style: TextStyle(color: MyColors.FF333333, fontSize: 15.r, fontWeight: FontWeight.bold)),
                                Visibility(
                                  visible: state.image.isNotEmpty,
                                  child: Image.memory(state.image, width: 75.r),
                                ),
                                SizedBox(
                                  width: 75.r,
                                  height: 30.r,
                                  child: BrnNormalButton(
                                    text: '点击签名',
                                    fontSize: 13.r,
                                    textColor: Colors.white,
                                    backgroundColor: MyColors.FF1060DD,
                                    insertPadding: const EdgeInsets.all(0),
                                    alignment: Alignment.center,
                                    borderRadius: BorderRadius.circular(4.r),
                                    onTap: () {
                                      logic.goToSignature();
                                    },
                                  ),
                                ),
                              ],
                            ),
                          ),
                        ),
                        Visibility(
                          visible: state.isVideo,
                          child: Container(
                            margin: EdgeInsets.fromLTRB(15.5.r, 10.5.r, 15.5.r, 10.5.r),
                            padding: EdgeInsets.only(left: 14.5.r, right: 24.r, top: 12.5.r, bottom: 16.5.r),
                            width: Get.width,
                            decoration: BoxDecoration(
                              color: Colors.white,
                              borderRadius: BorderRadius.all(Radius.circular(6.r)),
                            ),
                            child: Column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: [
                                Text("与被访者合照", style: TextStyle(color: MyColors.FF333333, fontSize: 15.r, fontWeight: FontWeight.bold)),
                                Container(
                                  padding: EdgeInsets.only(top: 14.r),
                                  child: ImagesGridviewWidget(
                                    onMediaResultsCallback: (List<Media> imagesList, filePathList) {
                                      state.imagesList = imagesList;
                                    },
                                  ),
                                ),
                              ],
                            ),
                          ),
                        ),
                      ],
                    ),
                  )
                ],
              ),
            ),
          ],
        ),
        bottomNavigationBar: SafeArea(
          child: Container(
            height: 45.r,
            margin: EdgeInsets.only(left: 16.r, right: 16.r, bottom: 12.r, top: 12.r),
            child: ElevatedButton(
              style: ElevatedButton.styleFrom(
                padding: const EdgeInsets.all(0),
                backgroundColor: MyColors.FF0144B0,
                shape: RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(6.r))),
              ),
              child: Text("完成调研", style: TextStyle(color: Colors.white, fontSize: 17.r)),
              onPressed: () {
                logic.complete();
              },
            ),
          ),
        ),
      );
    });
  }

  @override
  void dispose() {
    Get.delete<CompletePollLogic>();
    super.dispose();
  }
}
